package com.eagledata.project.business.fileInfo.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.eagledata.project.business.fileInfo.domain.FileInfo;
import com.eagledata.project.business.fileInfo.service.IFileInfoService;
import com.eagledata.framework.web.controller.BaseController;
import com.eagledata.framework.web.page.TableDataInfo;
import com.eagledata.framework.web.domain.Message;

/**
 * 文件 信息操作处理
 * 
 * @author eagledata
 * @date 2018-07-02
 */
@Controller
@RequestMapping("/business/fileInfo")
public class FileInfoController extends BaseController {
    private String prefix = "business/fileInfo";
	
	@Autowired
	private IFileInfoService fileInfoService;
	
	@RequestMapping()
	@RequiresPermissions("business:fileInfo:view")
	public String fileInfo() {
	    return prefix + "/fileInfo";
	}
	
	/**
	 * 查询文件列表
	 */
	@RequiresPermissions("business:fileInfo:list")
	@RequestMapping("/list")
	@ResponseBody
	public TableDataInfo list(FileInfo fileInfo) {
		startPage();
        List<FileInfo> list = fileInfoService.selectFileInfoList(fileInfo);
		return getDataTable(list);
	}
	
	/**
	 * 新增文件
	 */
	@RequiresPermissions("business:fileInfo:add")
	@RequestMapping("/add")
	public String add() {
	    return prefix + "/add";
	}

	/**
	 * 修改文件
	 */
	@RequiresPermissions("business:fileInfo:edit")
	@RequestMapping("/edit/{addr}")
	public String edit(@PathVariable("addr") String addr, Model model) {
		FileInfo fileInfo = fileInfoService.selectFileInfoById(addr);
		model.addAttribute("fileInfo", fileInfo);
	    return prefix + "/edit";
	}
	
	/**
	 * 保存文件
	 */
	@RequiresPermissions("business:fileInfo:save")
	@RequestMapping("/save")
	@ResponseBody
	public Message save(FileInfo fileInfo) {
		if (fileInfoService.saveFileInfo(fileInfo) > 0)
		{
			return Message.success();
		}
		return Message.error();
	}
	
	/**
	 * 删除文件
	 */
	@RequiresPermissions("business:fileInfo:remove")
	@RequestMapping( "/remove/{addr}")
	@ResponseBody
	public Message remove(@PathVariable("addr") String addr) {
		if (fileInfoService.deleteFileInfoById(addr) > 0)
		{
		    return Message.success();
		}
		return Message.error();
	}
	
	/**
	 * 批量删除文件
	 */
	@RequiresPermissions("business:fileInfo:batchRemove")
	@RequestMapping( "/batchRemove")
	@ResponseBody
	public Message remove(@RequestParam("ids[]") String[] addrs) {
		int rows = fileInfoService.batchDeleteFileInfo(addrs);
		if (rows > 0)
        {
            return Message.success();
        }
        return Message.error();
	}
	
}
